﻿using System;
using System.Collections.Generic;
using Autodesk.Revit.DB;
using YJKAreaCutter.Utils.InternalCorner;

namespace YJKAreaCutter.Utils
{
	public class GeometryCreateUtils
	{
		public static bool CreateSolid(IList<CurveLoop> profileLoops, XYZ extrusionDir, double dExtrusionDist, out Solid outSolid)
		{
			bool result = false;
			outSolid = null;
			try
			{
				outSolid = GeometryCreationUtilities.CreateExtrusionGeometry(profileLoops, extrusionDir, dExtrusionDist);
				result = true;
			}
			catch
			{
				List<CurveLoop> list = new List<CurveLoop>();
				IEnumerator<CurveLoop> enumerator = profileLoops.GetEnumerator();
				{
					while (enumerator.MoveNext())
					{
						CurveLoop item;
						if (CurveUtils.CreateConvexhullLoop(enumerator.Current, out item))
						{
							list.Add(item);
						}
					}
				}
				if (list.Count > 0)
				{
					outSolid = GeometryCreationUtilities.CreateExtrusionGeometry(list, extrusionDir, dExtrusionDist);
					result = true;
				}
			}
			return result;
		}
	}
}
